package junk;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;

public class wdtest2 {


    public WebDriver wd;

    /**
     * @param nodeURL node 节点的地址
     * @param browser node 节点的浏览器
     * @throws MalformedURLException
     */
    @Test
   /* @Parameters({"nodeURL", "browser", "browserversion"})*/
    @Parameters({"nodeURL", "browser"})
    //(dataProvider = "data") // 获取对应的数据源
    public void openBaiDuPageTest(String nodeURL, String browser/*, String browserversion*/) throws MalformedURLException {
        DesiredCapabilities desiredCapabilities;
//        判断要打开的浏览器


        if (browser.equals("chrome")) {
//            if (browser == "chrome") {


            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addArguments("--headless");
           // chromeOptions.addArguments("--headless","--disable-gpu","--window-size=1290,1080");
           // DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            desiredCapabilities = DesiredCapabilities.chrome();
            desiredCapabilities.setCapability("chromeOptions", chromeOptions);


        } else if (browser.equals("firefox")) {
            desiredCapabilities = DesiredCapabilities.firefox();
        } else {
            desiredCapabilities = DesiredCapabilities.internetExplorer();
        }
        /* else {
            desiredCapabilities = DesiredCapabilities.firefox();
        }*/

//        拼接处要执行脚本的node 节点地址
        // String url = nodeURL + "/wd/hub";
        String url = "http://192.168.1.7:4444/wd/hub";
        WebDriver driver = new RemoteWebDriver(new URL(url), desiredCapabilities);
//        打开百度
        driver.get("http://www.baidu.com");
        driver.findElement(By.name("wd")).clear();
        driver.findElement(By.name("wd")).sendKeys("oschina");
        driver.findElement(By.id("su")).click();
        // System.out.println(browser+browserversion +"--:--\n"+ driver.getTitle());
//        关闭浏览器
        try {
            Thread.sleep(2000);
            driver.quit();
            System.out.println("----close browser!!!-多浏览器测试--");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }
}
